/**
 *
 */
package com.wedroid.r2d2.support.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wedroid.r2d2.contact.Contact;
import com.wedroid.r2d2.support.sync.SyncKey;

/**
 * @author lute
 *
 */
public class InitResponse extends AbstractBaseResponse {

    private SyncKey syncKey;

    private Contact user;

    private List<Contact> contacts;

    /* (non-Javadoc)
     * @see com.wedroid.r2d2.support.response.AbstractBaseResponse#parseInternal(com.alibaba.fastjson.JSONObject)
     */
    @Override
    protected void parseInternal(JSONObject object) {
        syncKey = object.getObject("SyncKey", SyncKey.class);
        user = object.getObject("User", Contact.class);

        JSONArray contactList = object.getJSONArray("ContactList");
        contacts = new ArrayList<>();
        for (int i = 0; i < contactList.size(); i++) {
            contacts.add(contactList.getObject(i, Contact.class));
        }
    }

    /**
     * @return the syncKey
     */
    public SyncKey getSyncKey() {
        return syncKey;
    }

    /**
     * @return the user
     */
    public Contact getUser() {
        return user;
    }

    /**
     * @return the contacts
     */
    public List<Contact> getContacts() {
        return Collections.unmodifiableList(contacts);
    }

}
